<?php
/**
 * SoldState Class
 * 正在售出的状态
 *
 */

class SoldState implements State {

	public $gumballMachine = null;

	public function __construct($gumballMachine)
	{
		$this->gumballMachine = $gumballMachine;
	}

	// 投币
	public function insertCoin()
	{
		echo "Please wait, we're already giving you a gumball.\n";
	}	

	// 退币
	public function ejectCoin()
	{
		echo "Sorry, you already turned the crank.\n";
	}	

	// 转动摇柄
	public function turnCrank()
	{
		echo "Turning twice doesn't get you another gumball!\n";
	}

	// 发糖果
	public function dispense()
	{
		$this->gumballMachine->releaseBall();
		if($this->gumballMachine->getCount() > 0)
			$this->gumballMachine->setState($this->gumballMachine->getNoCoinState());
		else
		{
			echo "Oops, out of gumballs!\n";
			$this->gumballMachine->setState($this->gumballMachine->getSoldOutState());
		}
	}

	public function show()
	{
		return "dispensing a gumball.\n";
	}

}